package cqut.gbq.qimo.controller;

import cqut.gbq.qimo.entity.Assignment;
import cqut.gbq.qimo.entity.Record;
import cqut.gbq.qimo.entity.ResBean;
import cqut.gbq.qimo.entity.Student;
import cqut.gbq.qimo.mapper.AssignmentMapper;
import cqut.gbq.qimo.service.AssignmentService;
import cqut.gbq.qimo.service.RecordService;
import cqut.gbq.qimo.service.StudentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author leo
 * @create 2021-06-2115:59
 */
@Api(tags = "作业接口")
@RestController
public class AssignmentController {
    @Autowired
    private AssignmentService assignmentService;

    @Autowired
    private StudentsService studentsService;
    @Autowired
    private AssignmentMapper assignmentMapper;

    @Autowired
    private RecordService recordService;

    @ApiOperation("发布作业")
    @PostMapping("/createAssignment")
    private ResBean createAssignment(@RequestBody Assignment assignment){
        System.out.println(assignment);
        ResBean resBean = assignmentService.createAssignment(assignment);

        return resBean;
    }

    @ApiOperation("查询作也学生信息")
    @GetMapping("/getAssignmentDeatil")
    public ResBean getAssignmentDetail(@RequestParam Integer aid){
        System.out.println(aid);
        return assignmentService.getAssignmentDetail(aid);
    }


    @ApiOperation("查询作业详细信息")
    @GetMapping("/getAssignmentByAid")
    public ResBean getAssignmentByAid(@RequestParam Integer aid){
        System.out.println(aid);
        return assignmentService.getAssignmentByAid(aid);
    }


    @ApiOperation("修改成绩/打分")
    @PostMapping("/editScore")
    public ResBean editScore(@RequestParam Integer sid,@RequestParam Integer aid, @RequestParam Integer score,@RequestParam Integer ischeck){
        return assignmentService.editScore(sid,aid,score,ischeck);
    }

    @ApiOperation("删除作业")
    @DeleteMapping("/deleteAssignmentByAid")
    private ResBean deleteAssignmentByAid(@RequestParam Integer aid){
        boolean b = assignmentService.deleteAssignmentByAid(aid);

        if (b){
            return ResBean.success("删除成功");
        } else {
            return ResBean.error("删除失败");
        }
    }

    @ApiOperation("修改作业")
    @PostMapping("/editAssignment")
    private ResBean editAssignment(@RequestBody Assignment assignment){
        System.out.println(assignment);
        Integer row = assignmentService.editAssignment(assignment);

        if (row == 1){
            return ResBean.success("修改成功");
        } else {
            return ResBean.error("修改失败");
        }
    }

}
